﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace UcAsp
{
    // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明，
    // 请访问 http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(
               "ShowMessage", // 路由名称
               "ShowMessage/{id}", // 带有参数的 URL
               new { controller = "ShowMessage", action = "Index", id = UrlParameter.Optional } // 参数默认值
           );
            routes.MapRoute(
               "BaoMing", // 路由名称
               "BaoMing/{id}", // 带有参数的 URL
               new { controller = "BaoMing", action = "Index", id = UrlParameter.Optional } // 参数默认值
           );
            routes.MapRoute(
               "Talent", // 路由名称
               "Talent/{page}", // 带有参数的 URL
               new { controller = "Talent", action = "Index", id = UrlParameter.Optional } // 参数默认值
           );
            routes.MapRoute(
               "Works", // 路由名称
               "Works/{page}/{typeid}", // 带有参数的 URL
               new { controller = "Works", action = "Index", id = UrlParameter.Optional } // 参数默认值
           );
            routes.MapRoute(
               "Search", // 路由名称
               "Search/{keyword}/{page}", // 带有参数的 URL
               new { controller = "Search", action = "Index", id = UrlParameter.Optional } // 参数默认值
           );
            routes.MapRoute(
              "Infos", // 路由名称
              "Info/{ad}", // 带有参数的 URL
              new { controller = "Info", action = "Index", ad = UrlParameter.Optional } // 参数默认值
          );
            routes.MapRoute(
               "Info", // 路由名称
               "main/{ad}-{path}", // 带有参数的 URL
               new { controller = "Info", action = "Main", ad = UrlParameter.Optional, path = UrlParameter.Optional } // 参数默认值
           );
           
            routes.MapRoute(
                "Default", // 路由名称
                "{controller}/{action}/{id}", // 带有参数的 URL
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // 参数默认值
            );
            
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            // 默认情况下对 Entity Framework 使用 LocalDB
            Database.DefaultConnectionFactory = new SqlConnectionFactory(@"Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True");

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
           
        }
        void Application_Error(object sender, EventArgs e)
        {

            //WorkFrame.Parser.ErrorLog("UD2002", this.Server.GetLastError().Message, true);
            //this.Server.ClearError();
            //this.Response.Headers.Add("StatusCode", "404");
            //this.Response.Headers.Add("Status", "HTTP/1.0 404 Not Found");
            //Response.Write("Not Found<br>");
            //Response.Write("<br><br><br><br><br><br>");
            //Response.Write("----------------------------------------------------<br>");
            //Response.Write("<a href=\"http://www.ud2002.com\">悠点化妆学校</a>");

            //Response.End();
            
            
            
        }
    }
}